# encoding: utf-8
""" 
@version: v1.0 
@author: autumner 
@license: Apache Licence  
@contact: 18322313385@163.com 
@site:  
@software: PyCharm 
@file: class_new.py 
@time: 2019/6/25 12:52
"""

'''
通过__new()__方法创建一个未初始化的实例
'''

import time

class Date:
    def __init__(self, year, month, day):
        self.year = year
        self.month = month
        self.day = day

    @classmethod
    def today(cls):
        d = cls.__new__(cls)
        t = time.localtime()
        d.year = t.tm_year
        d.month = t.tm_mon
        d.day = t.tm_mday
        return d

#Example use

a = Date(2018, 6, 25)
b = Date.today()
print(a.year, a.month, a.day)
print(b.year, b.month, b.day)
print(vars(a))
print(vars(b))

import json
print(json.dumps(b, default=lambda obj:obj.__dict__, sort_keys=True, indent=4))